<template>
  <view class="page">
    <view v-if="list.length == 0" class="noneData"></view>

    <view class="image-text_2 flex-row justify-between mt20" v-for="(item, index) in list" :key="index">
      <image class="image_2" mode="aspectFill" :src="item.thumb_image" />
      <view class="block_3 flex-col justify-between">
        <text class="text-group_2" v-html="item.title"></text>

        <view class="align-center justify-end">
          <view class="delBtn" @click="bianji(item.id)"> 编辑 </view>
          <view class="delBtn" @click="shanchu(item.id)"> 删除 </view>
          <view class="delBtn" @click="shangjia(item.id)"> 上架 </view>
        </view>
      </view>
    </view>
  </view>
</template>
<script>
export default {
  data() {
    return {
      list: [],
      page: 1,
      total: 0
    };
  },
  onLoad(option) {
    this.getData();
  },
  onReachBottom(e) {
    if (this.list.length < this.total) {
      this.page++;
      this.getData(true);
    }
  },
  methods: {
    getData(type) {
      if (!type) {
        this.list = [];
      }
      var that = this;
      this.$http({ url: 'getCaoGao', data: { page: this.page } }).then((res) => {
        res.data.data.map((el) => {
          el.thumb_image = '';
        });
        that.list.push(...res.data.data);
        that.list.map((el) => {
          // el.thumb_imag = ''
          // let arr = el.url.split(',')
          // if (arr.length > 0 && !arr[0].endsWith('.mp4')) {
          //   el.thumb_image = arr[0]
          // } else {
          //   this.$http({
          //     url: 'upLoadFile',
          //     data: { file: arr[0] }
          //   }).then(res => {
          //     el.thumb_image = res.data.screen_shots_pic_url
          //   })
          // }
          if (el.thumb_image.endsWith('.mp4') || !el.thumb_image) el.thumb_image = el.thumb_image2;

          return el;
        });
        console.log(that.list);
        that.total = res.total;
      });
    },
    shanchu(id) {
      console.log(id);
      var that = this;
      uni.showModal({
        content: '确认删除吗',
        success: (res) => {
          if (res.confirm) {
            this.$http({
              url: 'articleDel',
              data: {
                id: id
              }
            }).then((res) => {
              this.getData();
              uni.showToast({
                title: '操作成功',
                icon: 'none' //
              });
            });
          }
        }
      });
    },

    shangjia(id) {
      var that = this;
      uni.showModal({
        content: '确认上架吗',
        success: (res) => {
          if (res.confirm) {
            uni.request({
              url: that.$global.baseUrl + 'articleEdit',
              method: 'GET',
              header: {
                token: this.$db.getToken()
              },
              data: {
                id: id,
                type: 1,
                status_switch: 2
              },
              success: (res) => {
                that.getData();
                uni.showToast({
                  title: '操作成功~',
                  icon: 'none', // 不显示图标，如果你想要显示图标可以设置为 'success'、'fail' 等
                  duration: 2000 // 持续时间，单位毫秒，默认1500
                });
              }
            });
          }
        }
      });
    },
    bianji(id) {
      console.log(id);
      uni.navigateTo({
        url: '/pages/publish/index?id=' + id
      });
    }
  }
};
</script>
<style lang="scss" scoped>
@import '../common/common.css';
.page {
  position: relative;
  width: 100%;
  background-color: #f8f8f8;
  min-height: 99vh;
  padding: 0 2.5%;
  overflow: hidden;
  overflow-y: scoll;
  padding-bottom: 50px;
}

.section_5 {
  position: relative;
  z-index: 2;
  margin-right: 20px;
}

.actText_4 {
  font-weight: 600;
  font-size: 18px;
  color: #111111;
}

.section_1 {
  width: 52rpx;
  height: 12rpx;
  background: url('../../static/img/dot.png') 100% no-repeat;
  background-size: 100% 100%;
  position: absolute;
  bottom: 2px;
  z-index: -1;
}

.image-text_2 {
  background-color: rgba(255, 255, 255, 1);
  border-radius: 6px;
  width: 100%;
  margin: 0 auto;
  padding: 30rpx;
  margin-top: 20rpx;
}

.image_2 {
  width: 160rpx;
  height: 160rpx;
  border-radius: 10px;
}

.block_3 {
  height: 160rpx;
  width: 70%;
}

.text-group_2 {
  color: rgba(51, 51, 51, 1);
  font-size: 15px;
  width: 100%;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

.delBtn {
  font-size: 15px;
  border-radius: 12px;
  border: 1px solid rgba(241, 241, 241, 1);
  text-align: center;
  margin-top: 10px;
  width: 120rpx;
  height: 60rpx;
  line-height: 60rpx;
  border-radius: 20px;
  margin-right: 10rpx;
}

.status {
  font-size: 12px;
}
.seeNum {
  font-size: 12px;
  color: #999999;
}
</style>
